package com.example.pokemon_integrado;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;

public class FadeOut {
	private Bitmap bMap;
	private float alpha;
	
	public FadeOut(Context context)
	{		
		this.bMap = BitmapFactory.decodeResource(context.getResources(), R.drawable.fade_out);
		this.alpha = 255;
	}
	
	public void Draw(Canvas canvas, int W, int H, Paint p)
	{
		canvas.drawBitmap(getResizedBitmap(this.bMap,W,H),0,0,p);
		p.setAlpha((int) this.alpha);
		
		if(this.alpha>0)
			this.alpha -= (W/W)*15;
		
	}
	
	public Bitmap getResizedBitmap(Bitmap bm, int newWidth, int newHeight) {

		int width = bm.getWidth();
		int height = bm.getHeight();

		float scaleWidth = ((float) newWidth) / width;
		float scaleHeight = ((float) newHeight) / height;

		Matrix matrix = new Matrix();
		matrix.postScale(scaleWidth, scaleHeight);
		
		Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, false);

		return resizedBitmap;

	}
}
